
const color = '#FF0000'
const opacity = 1

const uniforms = {
  time: {type: "float", value: 0},
  color: {type: "vec3",value: new THREE.Color(color)},
  opacity: { type: "float", value: opacity}
}

export default {
  uniforms: THREE.UniformsUtils.merge([THREE.UniformsLib.fog, uniforms]),
  vert: `
  precision lowp float;
  precision lowp int;
  #include <fog_pars_vertex>
  varying vec2 vUv;
  void main() {
      vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
      vUv = uv;
      gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
      #include <fog_vertex>
  }
  `,
  frag: `
  precision lowp float;
  precision lowp int;
  varying vec2 vUv;
  uniform float time;
  uniform vec3 color;
  uniform float opacity;

  #include <common>
  #include <fog_pars_fragment>

  void main() {
      vec2 uv = vUv - 0.5;
      float dir = length(uv);
      
      float r = dir*.85;
      r = r*2.-1.;
      float s = sin(pow(r+1., 2.)-time*3.+sin(r*.8))*sin(r+.99);
      vec3 col = color;
      col *= (abs(1./(s*60.8))-.01);
      gl_FragColor = vec4(col, 1.);
      
      float ratio = 0.25;
      if (dir < ratio) {
          gl_FragColor.a = opacity;
      } else {
          gl_FragColor.a = mix(opacity, 0., (dir - ratio) / (0.5 - ratio));
      }
      
      #include <fog_fragment>
  }
  `,
}